<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="/public :: #public_head"></head>
<body>
<header th:replace="/public :: #public_header"></header>
<section th:replace="/public :: #public_time"></section>
<!---->
<section class="publicMian ">
    <div class="left" th:replace="/public :: #public_left"></div>
    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>用户管理页面</span>
        </div>
<!--        form表单，查询用户-->
        <div class="search">
            <form id="searchForm" th:action="@{/users}" th:method="get">
                <span>用户名：</span>
                <input th:value="${username}" name="username" type="text" />
                <input type="submit" value="查询" onclick="$('#searchForm').submit()"/>
            </form>
            <a th:href="@{/user}" href="add.html">添加用户</a>
        </div>
        <table class="providerTable">
            <tr class="firstTr">
                <th >用户名</th>
                <th >真实姓名</th>
                <th >性别</th>
                <th >出生日期</th>
                <th >用户类型</th>
                <th >操作</th>
            </tr>
            <tr th:each="u:${users}" class="provider_tr">
                <td th:text="${u.username}">hanlu</td>
                <td th:text="${u.realName}">韩露</td>
                <td th:text="${u.gender == 1 ? '女':'男'}">女</td>
<!--                对时间格式化为YYYY-MM-dd -->
                <td th:text="${#dates.format(u.birthday,'yyyy-MM-dd')}">1999-01-01</td>
                <td th:text="${u.userType == 1 ? '管理员': (u.userType == 2 ? '经理' : '普通用户')}">管理员</td>
                <td>
                    <a href="view.html" th:href="@{/user/} + ${u.id}"><img th:src="@{/img/read.png}" src="../img/read.png" alt="查看" title="查看"/></a>
                    <a href="" th:href="@{/user/} + ${u.id} + '?type=update'"><img th:src="@{/img/xiugai.png}" src="../img/xiugai.png" alt="修改" title="修改"/></a>
                    <a th:attr="del_uri=@{/user/delete/} + ${u.id}" class="delete"><img th:src="@{/img/schu.png}" src="../img/schu.png" alt="删除" title="删除"/></a>
<!--                    <a href="#" id="del"><img th:src="@{/img/schu.png}" src="../img/schu.png" alt="删除" title="删除"/></a>-->
                </td>
            </tr>
        </table>
    </div>
</section>
<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<form method="post" id="deleteForm">
    <input type="hidden" name="_method" value="delete">
    <div class="remove" id="removeProv">
        <div class="removerChid">
            <h2>提示</h2>
            <div class="removeMain">
                <p>你确定要删除吗？</p>
                <a href="#" id="yes">确定</a>
                <a href="#" id="no">取消</a>
            </div>
        </div>
    </div>
</form>
<footer th:replace="/public :: #public_footer"/>
</body>
<script type="application/javascript" th:inline="javascript">
    $(function (){
    })
    function onDelete(id) {
        console.log(id)
//    弹出对话框，提示是否删除
        var r = confirm("是否删除该用户？");
        if (r == true) {
            console.log("删除")
            //thymeleaf行内表达式
            var url = [[@{/user/delete/}]] + id;
            $.ajax({
                url:url,
                dataType:'json',
                method:'delete',
                success: function (data) {
                    console.log(data)
                    if (data.code == 200){
                        alert("删除成功")
                        location.reload()
                    }else {
                        alert("删除失败")
                    }
                },
                error:function () {
                    alert("删除异常")
                }
            })
        }

    }
</script>
</html>